#pragma once
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <sstream>
#include <opencv.hpp>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#include "Half_thinning_Algorithm.h"
#include "Tools.h"
#include "Graph.h"
#include "GrahamImplementation.h"

using namespace std;
using namespace Tools;

class Ambigous_Zone_Based_Extraction
{
public:


	int run(const char* filename, vector<StrokeNode*> &stroke_graph, IplImage** ambigous_zones_map);
	Ambigous_Zone_Based_Extraction(void);
	virtual ~Ambigous_Zone_Based_Extraction(void);
private:
	
	// Writing's average width
	int w;
	// Source image
	IplImage *source_image;
	// Half thinned image
	IplImage *half_thinned_image;
	// Thinned image
	IplImage *thinned_image;

	set< CvPoint,ImagePointComp > Sf;
	set< CvPoint,ImagePointComp > Se;
	set< CvPoint,ImagePointComp > S1;
	vector< set< CvPoint,ImagePointComp > > Sa;

	void find_Candidate_Fork_Points();
	void find_End_Points();
	void find_Spurious_Candidate_Fork_Points();

	void process_Fork_Points();
	IplImage* detect_Ambigous_Zone(vector<StrokeNode*> &stroke_graph);
	void extract_Stroke();
	double calculate_dc(CvPoint pi);

	void visualize_fork_points();

};

